﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Kindohm.KSynth.Library;

namespace Kindohm.KSynth.UI
{
    public partial class NoteSettings : UserControl
    {
        public NoteSettings()
        {
            InitializeComponent();
            this.LoadLists();
        }

        void LoadLists()
        {
            List<NoteListItem> notes = new List<NoteListItem>();
            notes.Add(new NoteListItem() { Note = Note.A, Name = "A" });
            notes.Add(new NoteListItem() { Note = Note.AFlat, Name = "AFlat" });
            notes.Add(new NoteListItem() { Note = Note.ASharp, Name = "ASharp" });
            notes.Add(new NoteListItem() { Note = Note.B, Name = "B" });
            notes.Add(new NoteListItem() { Note = Note.BFlat, Name = "BFlat" });
            notes.Add(new NoteListItem() { Note = Note.BSharp, Name = "BSharp" });
            notes.Add(new NoteListItem() { Note = Note.C, Name = "C" });
            notes.Add(new NoteListItem() { Note = Note.CFlat, Name = "CFlat" });
            notes.Add(new NoteListItem() { Note = Note.CSharp, Name = "CSharp" });
            notes.Add(new NoteListItem() { Note = Note.D, Name = "D" });
            notes.Add(new NoteListItem() { Note = Note.DFlat, Name = "DFlat" });
            notes.Add(new NoteListItem() { Note = Note.DSharp, Name = "DSharp" });
            notes.Add(new NoteListItem() { Note = Note.E, Name = "E" });
            notes.Add(new NoteListItem() { Note = Note.EFlat, Name = "EFlat" });
            notes.Add(new NoteListItem() { Note = Note.F, Name = "F" });
            notes.Add(new NoteListItem() { Note = Note.FSharp, Name = "FSharp" });
            notes.Add(new NoteListItem() { Note = Note.G, Name = "G" });
            notes.Add(new NoteListItem() { Note = Note.GFlat, Name = "GFlat" });
            notes.Add(new NoteListItem() { Note = Note.GSharp, Name = "GSharp" });

            List<int> octaves = new List<int>();
            octaves.Add(1);
            octaves.Add(2);
            octaves.Add(3);
            octaves.Add(4);
            octaves.Add(5);
            octaves.Add(6);
            octaves.Add(7);
            octaves.Add(8);
            octaves.Add(9);
            octaves.Add(10);

            this.noteList.ItemsSource = notes;
            this.octaveList.ItemsSource = octaves;

        }

        public int YPosition
        {
            get;
            set;
        }

        public Note Note
        {
            get
            {
                return ((NoteListItem)this.noteList.SelectedItem).Note;
            }
            set
            {
                foreach (NoteListItem item in this.noteList.Items)
                {
                    if (item.Note == value)
                    {
                        this.noteList.SelectedItem = item;
                        break;
                    }
                }
            }
        }

        public int Octave
        {
            get
            {
                return (int)this.octaveList.SelectedItem;
            }
            set
            {
                this.octaveList.SelectedItem = value;
            }
        }

        public event EventHandler SettingsChanged;

        private void noteList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.SettingsChanged != null)
                this.SettingsChanged(this, EventArgs.Empty);
        }

        private void octaveList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.SettingsChanged != null)
                this.SettingsChanged(this, EventArgs.Empty);
        }

    }
}
